package com.sskj.mine.presenter;

import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonConverter;
import com.sskj.mine.asset.data.ExchangeRecordsBean;
import com.sskj.mine.ui.activity.ExchangeRecordsActivity;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Flowable;


/**
 * @author Hey
 * Create at  2019/05/04
 */
public class ExchangeRecordsPresenter extends BasePresenter<ExchangeRecordsActivity> {


    /**
     * 兑换记录
     *
     * @param p    页码，默认1
     * @param size 页条数，默认5
     * @return
     */
    public Flowable<List<ExchangeRecordsBean>> getCashRecord(String p, String size) {
        return httpService.getCashRecord(p, size)
                .converter(new JsonConverter<HttpData<PageBean<ExchangeRecordsBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(pageBeanHttpData -> pageBeanHttpData.getData().getList())
                .onErrorReturnItem(new ArrayList<>());
    }
}
